#[test]
fn test_vector(){
    let mut list: Vec<i32> = Vec::new();
    list.push(12);
    list.push(13);
    println!("{:?}", list);
    let list2 = vec![1i32,2,3,4,5];
    println!("{:?}", list2);
    let v0: i32 = *list.get(0).unwrap();
    println!("list[0] = {:?}", v0);

    list.append(&mut list2.clone());
    println!("{:?} {:?}", list, list2);

    list.remove(0);
    list.remove(0);
    println!("{:?}", list);

    // .iter()返回一个新迭代器，原来的不受影响
    let list2: Vec<_> = list.iter().map(|x| *x*2).collect();
    println!("{:?}", list2);

    // .into_iter()返回一个获得所有权的迭代器，原来的所有权将会move到新的迭代器里
    // 可以用此特性对vector实现复杂的操作
    list = list.iter()
        .map(|x|x+1)
        .filter(|x|*x>3)
        .skip(1)
        .collect();
    println!("{:?}", list);

    let count = list2.iter()
        .map(|x|*x / 2)
        .skip(2)
        .count();

    println!("{:?} {}",list2, count)

}

// 数组快速生成
#[test]
fn test_arr_gen(){
    let mut list: Vec<i32> = (1..101)
        .map(|x|x*2)
        .filter(|&x|x%4 == 0 )
        .filter(|&x|x%6 == 0)
        .collect();

    list.sort_by(|a,b|b.cmp(a));
    let list = list.into_iter().take(5).skip(2).count();

    println!("{:?}", list);
}
